#include "exporttool.h"
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include "common/common.h"

ExportTool::ExportTool(QObject* parent)
{

}

void ExportTool::exportToFile(const QByteArray &arr, const QString &fileName)
{
//    QFile file(fileName);
//    if(file.exists)
//    {

//    }
}

void ExportTool::writeLineToFile(const QByteArray &lineArr, const QString &fileName,int type)
{
    QDir dir(USB);
    bool needHead = false;
    if(!dir.exists())
    {
        qDebug()<<dir.dirName()<<" is not exist";
        return;
    }
    QFile* file = new QFile(USB+fileName);
    if(!file->exists())
    {
        needHead = true;
    }
    if(!file->open(QIODevice::WriteOnly|QIODevice::Append))
    {
        qDebug()<<file->errorString();
        return;

    }
    if(needHead)
    {   QByteArray headArr;
        switch (type) {
        case CHECK:
            headArr ="日期,时间,产品名,净重,皮重,毛重,上限,标准值,下限,检重结果,操作员\r\n";
            break;
        case CLASS:
            headArr ="日期,时间,产品名,净重,皮重,毛重,区间,检重结果,操作员\r\n";
            break;
        default:
            break;
        }
        file->write(headArr);
    }
    file->write(lineArr);
    file->close();
    delete file;
}

